package orange.data;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Filemanager {
	public static String FileReader(String path) throws Exception {
		ArrayList<String> list = new ArrayList<String>();
		InputStream in = new FileInputStream(new File(path));
		BufferedReader r = new BufferedReader(
				new InputStreamReader(in, "UTF-8"));
		String line;
		StringBuffer sb = new StringBuffer();
		while ((line = r.readLine()) != null) {
//			list.add(line.trim().split(",")[1].replace("\"", ""));
			sb.append(line).append("\n");
		}
		r.close();
		in.close();
		return sb.toString();
	}
	// 将文件保存到本地
	public static  boolean saveDocument(String str,String filename) {		
		String path="/";
		try {
			File dirfile=new File(path);
			if(!dirfile.exists())
				dirfile.mkdir();//第一次创建目录
			
			File file = new File(path+filename); // 第二次创建这个文件就会把第一次的文件覆盖掉
			FileOutputStream fos = new FileOutputStream(file);
			fos.write(str.getBytes());
			fos.flush();
			fos.close();
			return true;
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}
}
